<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        console.log("global begin:"+i);
        //输出 undefined
        var i=1;
        foo(1);
        /*
        输出答案：
        foo() begin:1
        foo() begin:2
        foo() begin:3
        foo() end:3
        foo() end:2
        foo() end:1
        global end:1
        */
        function foo(i)
        {
            if(i == 4)
            {
                return;
            }
            console.log("foo() begin:"+i);
            foo(i+1);//注意局部变量和全局变量的传递
            console.log("foo() end:"+i);
        }
        console.log("global end:"+i);
    </script>
</head>
<body>
    <!--
        1.依次输出什么
        undefined
        foo() begin:1
        foo() begin:2
        foo() begin:3
        foo() end:3
        foo() end:2
        foo() end:1
        global end:1
        2.真个过程中产生了几个执行上下文
        5个
    -->
</body>
</html>